package homework03;

public class ThreadDemo03 implements Runnable{
    private int notes = 80;
    @Override
    public void run() {
        while (true){
            distribute();
            if (notes <= 0){
                break;
            }
        }
    }
    public synchronized void distribute(){
        if (notes > 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "发出的笔记:" + notes--);
        }
    }

    public static void main(String[] args) {
        ThreadDemo03 th = new ThreadDemo03();
        for (int i = 0; i < 3; i++) {
            new Thread(th, "老师" + (i+1)).start();
        }
       /* new Thread(th, "陈老师").start();
        new Thread(th, "高老师").start();
        new Thread(th, "李老师").start();*/
    }
}
